{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "LinearRegression.ipynb",
      "provenance": [],
      "toc_visible": true,
      "authorship_tag": "ABX9TyM3xX5HVfJ2KDmjKRAqy3wW",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/maanasvi999/LinearRegression/blob/main/LinearRegression.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YmqX_MYUnGes"
      },
      "source": [
        "# **Linear Regression**"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "4PYfh1C0nK-p"
      },
      "source": [
        "Linear regression is a linear model, e.g. a model that assumes a linear relationship between the input variables (x) and the single output variable (y). More specifically, that y can be calculated from a linear combination of the input variables (x)."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "v1xdrl7LnlvH"
      },
      "source": [
        "Following is Code Implementation for Calculating the Life Expectancy of a human in any country using Linear Regression"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "9NBlF7deXUTS"
      },
      "source": [
        "import pandas as pd\n",
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "import seaborn as sns\n",
        "%matplotlib inline"
      ],
      "execution_count": 1,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 278
        },
        "id": "bVMKjTBrXamW",
        "outputId": "370a423b-6abb-4f3a-90e9-7106924d12a6"
      },
      "source": [
        "df_data = pd.read_csv('Life Expectancy Data.csv')\n",
        "df_data.head()"
      ],
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Country</th>\n",
              "      <th>Year</th>\n",
              "      <th>Status</th>\n",
              "      <th>Life expectancy</th>\n",
              "      <th>Adult Mortality</th>\n",
              "      <th>infant deaths</th>\n",
              "      <th>Alcohol</th>\n",
              "      <th>percentage expenditure</th>\n",
              "      <th>Hepatitis B</th>\n",
              "      <th>Measles</th>\n",
              "      <th>BMI</th>\n",
              "      <th>under-five deaths</th>\n",
              "      <th>Polio</th>\n",
              "      <th>Total expenditure</th>\n",
              "      <th>Diphtheria</th>\n",
              "      <th>HIV/AIDS</th>\n",
              "      <th>GDP</th>\n",
              "      <th>Population</th>\n",
              "      <th>thinness  1-19 years</th>\n",
              "      <th>thinness 5-9 years</th>\n",
              "      <th>Income composition of resources</th>\n",
              "      <th>Schooling</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Afghanistan</td>\n",
              "      <td>2015</td>\n",
              "      <td>Developing</td>\n",
              "      <td>65.0</td>\n",
              "      <td>263.0</td>\n",
              "      <td>62</td>\n",
              "      <td>0.01</td>\n",
              "      <td>71.279624</td>\n",
              "      <td>65.0</td>\n",
              "      <td>1154</td>\n",
              "      <td>19.1</td>\n",
              "      <td>83</td>\n",
              "      <td>6.0</td>\n",
              "      <td>8.16</td>\n",
              "      <td>65.0</td>\n",
              "      <td>0.1</td>\n",
              "      <td>584.259210</td>\n",
              "      <td>33736494.0</td>\n",
              "      <td>17.2</td>\n",
              "      <td>17.3</td>\n",
              "      <td>0.479</td>\n",
              "      <td>10.1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Afghanistan</td>\n",
              "      <td>2014</td>\n",
              "      <td>Developing</td>\n",
              "      <td>59.9</td>\n",
              "      <td>271.0</td>\n",
              "      <td>64</td>\n",
              "      <td>0.01</td>\n",
              "      <td>73.523582</td>\n",
              "      <td>62.0</td>\n",
              "      <td>492</td>\n",
              "      <td>18.6</td>\n",
              "      <td>86</td>\n",
              "      <td>58.0</td>\n",
              "      <td>8.18</td>\n",
              "      <td>62.0</td>\n",
              "      <td>0.1</td>\n",
              "      <td>612.696514</td>\n",
              "      <td>327582.0</td>\n",
              "      <td>17.5</td>\n",
              "      <td>17.5</td>\n",
              "      <td>0.476</td>\n",
              "      <td>10.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Afghanistan</td>\n",
              "      <td>2013</td>\n",
              "      <td>Developing</td>\n",
              "      <td>59.9</td>\n",
              "      <td>268.0</td>\n",
              "      <td>66</td>\n",
              "      <td>0.01</td>\n",
              "      <td>73.219243</td>\n",
              "      <td>64.0</td>\n",
              "      <td>430</td>\n",
              "      <td>18.1</td>\n",
              "      <td>89</td>\n",
              "      <td>62.0</td>\n",
              "      <td>8.13</td>\n",
              "      <td>64.0</td>\n",
              "      <td>0.1</td>\n",
              "      <td>631.744976</td>\n",
              "      <td>31731688.0</td>\n",
              "      <td>17.7</td>\n",
              "      <td>17.7</td>\n",
              "      <td>0.470</td>\n",
              "      <td>9.9</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Afghanistan</td>\n",
              "      <td>2012</td>\n",
              "      <td>Developing</td>\n",
              "      <td>59.5</td>\n",
              "      <td>272.0</td>\n",
              "      <td>69</td>\n",
              "      <td>0.01</td>\n",
              "      <td>78.184215</td>\n",
              "      <td>67.0</td>\n",
              "      <td>2787</td>\n",
              "      <td>17.6</td>\n",
              "      <td>93</td>\n",
              "      <td>67.0</td>\n",
              "      <td>8.52</td>\n",
              "      <td>67.0</td>\n",
              "      <td>0.1</td>\n",
              "      <td>669.959000</td>\n",
              "      <td>3696958.0</td>\n",
              "      <td>17.9</td>\n",
              "      <td>18.0</td>\n",
              "      <td>0.463</td>\n",
              "      <td>9.8</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Afghanistan</td>\n",
              "      <td>2011</td>\n",
              "      <td>Developing</td>\n",
              "      <td>59.2</td>\n",
              "      <td>275.0</td>\n",
              "      <td>71</td>\n",
              "      <td>0.01</td>\n",
              "      <td>7.097109</td>\n",
              "      <td>68.0</td>\n",
              "      <td>3013</td>\n",
              "      <td>17.2</td>\n",
              "      <td>97</td>\n",
              "      <td>68.0</td>\n",
              "      <td>7.87</td>\n",
              "      <td>68.0</td>\n",
              "      <td>0.1</td>\n",
              "      <td>63.537231</td>\n",
              "      <td>2978599.0</td>\n",
              "      <td>18.2</td>\n",
              "      <td>18.2</td>\n",
              "      <td>0.454</td>\n",
              "      <td>9.5</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "       Country  Year  ... Income composition of resources  Schooling\n",
              "0  Afghanistan  2015  ...                           0.479       10.1\n",
              "1  Afghanistan  2014  ...                           0.476       10.0\n",
              "2  Afghanistan  2013  ...                           0.470        9.9\n",
              "3  Afghanistan  2012  ...                           0.463        9.8\n",
              "4  Afghanistan  2011  ...                           0.454        9.5\n",
              "\n",
              "[5 rows x 22 columns]"
            ]
          },
          "metadata": {},
          "execution_count": 2
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "cXhZuxRlYKbB"
      },
      "source": [
        "df_data=df_data.fillna(0)"
      ],
      "execution_count": 4,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "zB9w8Io1YNWK"
      },
      "source": [
        "df_data['Status']=df_data['Status'].map({'Developing':0,'Developed':1})"
      ],
      "execution_count": 6,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "oIAobBjiYQXE",
        "outputId": "ef86d141-1d44-4ad5-ea1d-5053685b7596"
      },
      "source": [
        "df_data.info()"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "RangeIndex: 2938 entries, 0 to 2937\n",
            "Data columns (total 22 columns):\n",
            " #   Column                           Non-Null Count  Dtype  \n",
            "---  ------                           --------------  -----  \n",
            " 0   Country                          2938 non-null   object \n",
            " 1   Year                             2938 non-null   int64  \n",
            " 2   Status                           2938 non-null   int64  \n",
            " 3   Life expectancy                  2938 non-null   float64\n",
            " 4   Adult Mortality                  2938 non-null   float64\n",
            " 5   infant deaths                    2938 non-null   int64  \n",
            " 6   Alcohol                          2938 non-null   float64\n",
            " 7   percentage expenditure           2938 non-null   float64\n",
            " 8   Hepatitis B                      2938 non-null   float64\n",
            " 9   Measles                          2938 non-null   int64  \n",
            " 10   BMI                             2938 non-null   float64\n",
            " 11  under-five deaths                2938 non-null   int64  \n",
            " 12  Polio                            2938 non-null   float64\n",
            " 13  Total expenditure                2938 non-null   float64\n",
            " 14  Diphtheria                       2938 non-null   float64\n",
            " 15   HIV/AIDS                        2938 non-null   float64\n",
            " 16  GDP                              2938 non-null   float64\n",
            " 17  Population                       2938 non-null   float64\n",
            " 18   thinness  1-19 years            2938 non-null   float64\n",
            " 19   thinness 5-9 years              2938 non-null   float64\n",
            " 20  Income composition of resources  2938 non-null   float64\n",
            " 21  Schooling                        2938 non-null   float64\n",
            "dtypes: float64(16), int64(5), object(1)\n",
            "memory usage: 505.1+ KB\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 372
        },
        "id": "bVwyPlv9YWw1",
        "outputId": "aca358e3-7501-41b8-fa28-eab9cc1daed3"
      },
      "source": [
        "df_data.describe()"
      ],
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Year</th>\n",
              "      <th>Status</th>\n",
              "      <th>Life expectancy</th>\n",
              "      <th>Adult Mortality</th>\n",
              "      <th>infant deaths</th>\n",
              "      <th>Alcohol</th>\n",
              "      <th>percentage expenditure</th>\n",
              "      <th>Hepatitis B</th>\n",
              "      <th>Measles</th>\n",
              "      <th>BMI</th>\n",
              "      <th>under-five deaths</th>\n",
              "      <th>Polio</th>\n",
              "      <th>Total expenditure</th>\n",
              "      <th>Diphtheria</th>\n",
              "      <th>HIV/AIDS</th>\n",
              "      <th>GDP</th>\n",
              "      <th>Population</th>\n",
              "      <th>thinness  1-19 years</th>\n",
              "      <th>thinness 5-9 years</th>\n",
              "      <th>Income composition of resources</th>\n",
              "      <th>Schooling</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>count</th>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2.938000e+03</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.000000</td>\n",
              "      <td>2938.00000</td>\n",
              "      <td>2938.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mean</th>\n",
              "      <td>2007.518720</td>\n",
              "      <td>0.174268</td>\n",
              "      <td>68.989312</td>\n",
              "      <td>164.235534</td>\n",
              "      <td>30.303948</td>\n",
              "      <td>4.298928</td>\n",
              "      <td>738.251295</td>\n",
              "      <td>65.705582</td>\n",
              "      <td>2419.592240</td>\n",
              "      <td>37.877774</td>\n",
              "      <td>42.035739</td>\n",
              "      <td>82.016338</td>\n",
              "      <td>5.481406</td>\n",
              "      <td>81.791695</td>\n",
              "      <td>1.742103</td>\n",
              "      <td>6342.091419</td>\n",
              "      <td>9.923150e+06</td>\n",
              "      <td>4.783696</td>\n",
              "      <td>4.813955</td>\n",
              "      <td>0.59188</td>\n",
              "      <td>11.327434</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>std</th>\n",
              "      <td>4.613841</td>\n",
              "      <td>0.379405</td>\n",
              "      <td>10.327437</td>\n",
              "      <td>124.451093</td>\n",
              "      <td>117.926501</td>\n",
              "      <td>4.079748</td>\n",
              "      <td>1987.914858</td>\n",
              "      <td>38.878316</td>\n",
              "      <td>11467.272489</td>\n",
              "      <td>20.344920</td>\n",
              "      <td>160.445548</td>\n",
              "      <td>24.271835</td>\n",
              "      <td>2.875063</td>\n",
              "      <td>24.544100</td>\n",
              "      <td>5.077785</td>\n",
              "      <td>13409.501883</td>\n",
              "      <td>5.407586e+07</td>\n",
              "      <td>4.424924</td>\n",
              "      <td>4.512880</td>\n",
              "      <td>0.25114</td>\n",
              "      <td>4.265626</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>min</th>\n",
              "      <td>2000.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.100000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000e+00</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.00000</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25%</th>\n",
              "      <td>2004.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>63.000000</td>\n",
              "      <td>73.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>0.470000</td>\n",
              "      <td>4.685343</td>\n",
              "      <td>24.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>19.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>77.000000</td>\n",
              "      <td>3.740000</td>\n",
              "      <td>78.000000</td>\n",
              "      <td>0.100000</td>\n",
              "      <td>190.174435</td>\n",
              "      <td>5.874250e+03</td>\n",
              "      <td>1.500000</td>\n",
              "      <td>1.500000</td>\n",
              "      <td>0.46500</td>\n",
              "      <td>9.500000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>50%</th>\n",
              "      <td>2008.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>72.000000</td>\n",
              "      <td>144.000000</td>\n",
              "      <td>3.000000</td>\n",
              "      <td>3.130000</td>\n",
              "      <td>64.912906</td>\n",
              "      <td>87.000000</td>\n",
              "      <td>17.000000</td>\n",
              "      <td>43.000000</td>\n",
              "      <td>4.000000</td>\n",
              "      <td>93.000000</td>\n",
              "      <td>5.540000</td>\n",
              "      <td>93.000000</td>\n",
              "      <td>0.100000</td>\n",
              "      <td>1171.983435</td>\n",
              "      <td>5.393575e+05</td>\n",
              "      <td>3.300000</td>\n",
              "      <td>3.300000</td>\n",
              "      <td>0.66200</td>\n",
              "      <td>12.100000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>75%</th>\n",
              "      <td>2012.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>75.600000</td>\n",
              "      <td>227.000000</td>\n",
              "      <td>22.000000</td>\n",
              "      <td>7.390000</td>\n",
              "      <td>441.534144</td>\n",
              "      <td>96.000000</td>\n",
              "      <td>360.250000</td>\n",
              "      <td>56.100000</td>\n",
              "      <td>28.000000</td>\n",
              "      <td>97.000000</td>\n",
              "      <td>7.330000</td>\n",
              "      <td>97.000000</td>\n",
              "      <td>0.800000</td>\n",
              "      <td>4779.405190</td>\n",
              "      <td>4.584371e+06</td>\n",
              "      <td>7.100000</td>\n",
              "      <td>7.200000</td>\n",
              "      <td>0.77200</td>\n",
              "      <td>14.100000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>max</th>\n",
              "      <td>2015.000000</td>\n",
              "      <td>1.000000</td>\n",
              "      <td>89.000000</td>\n",
              "      <td>723.000000</td>\n",
              "      <td>1800.000000</td>\n",
              "      <td>17.870000</td>\n",
              "      <td>19479.911610</td>\n",
              "      <td>99.000000</td>\n",
              "      <td>212183.000000</td>\n",
              "      <td>87.300000</td>\n",
              "      <td>2500.000000</td>\n",
              "      <td>99.000000</td>\n",
              "      <td>17.600000</td>\n",
              "      <td>99.000000</td>\n",
              "      <td>50.600000</td>\n",
              "      <td>119172.741800</td>\n",
              "      <td>1.293859e+09</td>\n",
              "      <td>27.700000</td>\n",
              "      <td>28.600000</td>\n",
              "      <td>0.94800</td>\n",
              "      <td>20.700000</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "              Year       Status  ...  Income composition of resources    Schooling\n",
              "count  2938.000000  2938.000000  ...                       2938.00000  2938.000000\n",
              "mean   2007.518720     0.174268  ...                          0.59188    11.327434\n",
              "std       4.613841     0.379405  ...                          0.25114     4.265626\n",
              "min    2000.000000     0.000000  ...                          0.00000     0.000000\n",
              "25%    2004.000000     0.000000  ...                          0.46500     9.500000\n",
              "50%    2008.000000     0.000000  ...                          0.66200    12.100000\n",
              "75%    2012.000000     0.000000  ...                          0.77200    14.100000\n",
              "max    2015.000000     1.000000  ...                          0.94800    20.700000\n",
              "\n",
              "[8 rows x 21 columns]"
            ]
          },
          "metadata": {},
          "execution_count": 9
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "lW6xgHSHYZxN",
        "outputId": "1be3219b-be9c-42cb-9448-0e56d44b00d7"
      },
      "source": [
        "df_data.columns"
      ],
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Index(['Country', 'Year', 'Status', 'Life expectancy ', 'Adult Mortality',\n",
              "       'infant deaths', 'Alcohol', 'percentage expenditure', 'Hepatitis B',\n",
              "       'Measles ', ' BMI ', 'under-five deaths ', 'Polio', 'Total expenditure',\n",
              "       'Diphtheria ', ' HIV/AIDS', 'GDP', 'Population',\n",
              "       ' thinness  1-19 years', ' thinness 5-9 years',\n",
              "       'Income composition of resources', 'Schooling'],\n",
              "      dtype='object')"
            ]
          },
          "metadata": {},
          "execution_count": 10
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "O5L1_49BYd8U"
      },
      "source": [
        "X = df_data[['Year', 'Status', 'Adult Mortality',\n",
        "       'infant deaths', 'Alcohol', 'percentage expenditure', 'Hepatitis B',\n",
        "       'Measles ', ' BMI ', 'under-five deaths ', 'Polio', 'Total expenditure',\n",
        "       'Diphtheria ', ' HIV/AIDS', 'GDP', 'Population',\n",
        "       ' thinness  1-19 years', ' thinness 5-9 years',\n",
        "       'Income composition of resources', 'Schooling']]\n",
        "y = df_data['Life expectancy ']"
      ],
      "execution_count": 11,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "n8Sl15wkYmWc"
      },
      "source": [
        "from sklearn.model_selection import train_test_split"
      ],
      "execution_count": 12,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "0sx-6DjIYmS_"
      },
      "source": [
        "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=101)"
      ],
      "execution_count": 13,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "VBtqjelQYmQh"
      },
      "source": [
        "from sklearn.linear_model import LinearRegression"
      ],
      "execution_count": 14,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "tsMy_0GpYmNt"
      },
      "source": [
        "lm = LinearRegression()"
      ],
      "execution_count": 15,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "lutbOHWtYsiL",
        "outputId": "bfd61705-c8cb-4565-e415-1db1a1a9425a"
      },
      "source": [
        "lm.fit(X_train,y_train)"
      ],
      "execution_count": 16,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False)"
            ]
          },
          "metadata": {},
          "execution_count": 16
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "pz3QULKNYse4",
        "outputId": "47258d32-e807-4b76-8a54-62f5878d81ee"
      },
      "source": [
        "print(lm.intercept_)"
      ],
      "execution_count": 17,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "68.70650014717911\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 676
        },
        "id": "TpZBL3m3Yscm",
        "outputId": "7f35c473-356d-458e-d343-ecd95c84914a"
      },
      "source": [
        "coeff_df = pd.DataFrame(lm.coef_,X.columns,columns=['Coefficient'])\n",
        "coeff_df"
      ],
      "execution_count": 18,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Coefficient</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>Year</th>\n",
              "      <td>-5.048710e-03</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Status</th>\n",
              "      <td>2.869336e+00</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Adult Mortality</th>\n",
              "      <td>-1.558896e-02</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>infant deaths</th>\n",
              "      <td>1.381803e-01</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Alcohol</th>\n",
              "      <td>2.928758e-01</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>percentage expenditure</th>\n",
              "      <td>-1.286444e-04</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Hepatitis B</th>\n",
              "      <td>1.022886e-02</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Measles</th>\n",
              "      <td>-2.588137e-07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>BMI</th>\n",
              "      <td>4.377338e-02</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>under-five deaths</th>\n",
              "      <td>-1.041321e-01</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Polio</th>\n",
              "      <td>3.052280e-02</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Total expenditure</th>\n",
              "      <td>-8.141478e-02</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Diphtheria</th>\n",
              "      <td>1.914229e-02</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>HIV/AIDS</th>\n",
              "      <td>-5.048269e-01</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>GDP</th>\n",
              "      <td>8.218849e-05</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Population</th>\n",
              "      <td>-4.945320e-10</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>thinness  1-19 years</th>\n",
              "      <td>-1.025264e-01</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>thinness 5-9 years</th>\n",
              "      <td>2.613654e-02</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Income composition of resources</th>\n",
              "      <td>6.667783e+00</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Schooling</th>\n",
              "      <td>2.053480e-01</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "                                  Coefficient\n",
              "Year                            -5.048710e-03\n",
              "Status                           2.869336e+00\n",
              "Adult Mortality                 -1.558896e-02\n",
              "infant deaths                    1.381803e-01\n",
              "Alcohol                          2.928758e-01\n",
              "percentage expenditure          -1.286444e-04\n",
              "Hepatitis B                      1.022886e-02\n",
              "Measles                         -2.588137e-07\n",
              " BMI                             4.377338e-02\n",
              "under-five deaths               -1.041321e-01\n",
              "Polio                            3.052280e-02\n",
              "Total expenditure               -8.141478e-02\n",
              "Diphtheria                       1.914229e-02\n",
              " HIV/AIDS                       -5.048269e-01\n",
              "GDP                              8.218849e-05\n",
              "Population                      -4.945320e-10\n",
              " thinness  1-19 years           -1.025264e-01\n",
              " thinness 5-9 years              2.613654e-02\n",
              "Income composition of resources  6.667783e+00\n",
              "Schooling                        2.053480e-01"
            ]
          },
          "metadata": {},
          "execution_count": 18
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "89luTRMmYsaT"
      },
      "source": [
        "predictions = lm.predict(X_test)"
      ],
      "execution_count": 19,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 285
        },
        "id": "Krmcssb1YsYG",
        "outputId": "161adf66-ad5a-47c9-ac07-4ba8841a687e"
      },
      "source": [
        "plt.scatter(y_test,predictions)"
      ],
      "execution_count": 20,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "<matplotlib.collections.PathCollection at 0x7fc52ee21f10>"
            ]
          },
          "metadata": {},
          "execution_count": 20
        },
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD7CAYAAABzGc+QAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3db5Bc1Znf8e8zrZbpkSu0hGcpaCNLXrukGCuSzJStlDYuCzbIuxiYYAymoIpsvOHNVtZonYnHWy4LXDjIpc0av0g2RexskTLB4p8HvKqycCE5lVCBzYxHMsaWYps/gpaAsdGwjtRGPaOTF9131NNz7+3b3be77+3+fd5o+nZPz5mmeeb0c57zHHPOISIi6TPU6wGIiEhrFMBFRFJKAVxEJKUUwEVEUkoBXEQkpRTARURSKlIAN7PPm9lPzewFM7uzem2Nmf3QzH5R/Xd1Z4cqIiK1GgZwM/sw8K+BjwKbgU+Z2QeACeBp59wHgaert0VEpEtWRHjMPwaec86dATCz/wHcAFwPfKL6mAeAHwFfDHui97znPW7dunUtDlVEZDBNT0//2jk3Un89SgD/KfA1M7sIKAF/DEwBFzvnTlYf8zpwsd83m9kdwB0Aa9euZWpqqoXhi4gMLjN7xe96wxSKc+7nwNeBp4AfAIeBhbrHOMB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f8wCldfhgerDBqqhmBqsLWVmFwIfp7ofwzl31jk3xwC/R6iUSefMbAUwDJykz94jaQjgBeDVmtuBjbMGgZmtA7YCzwEXO+dOVu96Hbi4R8PqhZYbrPWp9cAs8LfVtNK3zGwVA/oecc4Vgb8CjlMJ3G8D0/TZeyQNAVyqzOzdwGPAnc65f6i9z1XqQQeiJrTdBmt9agXwEeBvnHNbgdPUpUsG7D2ymsqnj/XApcAq4JM9HVQHpCGAF4HLam5HapzVb8wsSyV4P+ice7x6+Q0zu6R6/yXAm70aX5d5DdZeppJSu5KaBmvVxwza++Q14DXn3HPV249SCeiD+h75Q+Al59ysc64MPE7lfdNX75E0BPD/A3ywunq8kspCxJM9HlNXVfO73wZ+7pz765q7ngRur359O/BEt8fWC865Lznn3uucW0fl/XDQOXcrcAi4sfqwgXk9AJxzrwOvmtmG6qWrgJ8xoO8RKqmTbWY2XP3/x3s9+uo9koqdmNVWtvdRWUn+r865r/V4SF1lZn8A/E/gec7nfP+SSh78YWAt8Apwk3PurZ4MskfqOmS+n8qMfA0wA9zmnHunl+PrJjPbQmVRdyXwIvAnVCZpA/keMbO7gZupVHHNAH9KJefdN++RVARwERFZLg0pFBER8aEALiKSUgrgIiIppQAuIpJSCuAiIimlAC4iklIK4CIiKfX/AWysE9oJoOhrAAAAAElFTkSuQmCC\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "y5WG7ezmmcYu"
      },
      "source": [
        ""
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3HMAsdRCZhXB"
      },
      "source": [
        "Metrics to calculate MAE, MSE, RMSE"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "yDlPH-tnY-39",
        "outputId": "10f65aca-ce05-4a6d-d465-04a74b92a583"
      },
      "source": [
        "from sklearn import metrics\n",
        "print('MAE:', metrics.mean_absolute_error(y_test, predictions))\n",
        "print('MSE:', metrics.mean_squared_error(y_test, predictions))\n",
        "print('RMSE:', np.sqrt(metrics.mean_squared_error(y_test, predictions)))"
      ],
      "execution_count": 21,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "MAE: 3.3592014981074465\n",
            "MSE: 28.427788801424363\n",
            "RMSE: 5.331771638154091\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "GDBsyplNnyPL"
      },
      "source": [
        "\n",
        "\n",
        "> Above created Linear Regression Model can be connected to the backend of a form to get output on a web application. The output would look something like this:\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "MMVZMRv5oSHW"
      },
      "source": [
        "![image.png]()"
      ]
    }
  ]
}